package com.five.wisdomClass.controller;


import com.five.wisdomClass.bean.ResponseData;
import com.five.wisdomClass.entity.Announce;
import com.five.wisdomClass.entity.Leave;

import com.five.wisdomClass.service.IAdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Tag(name="管理员的基本操作")
@Slf4j
@RestController
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/admin")
public class AdminController extends BaseController{

    private final IAdminService adminService;

    @Operation(summary = "发布公告")
    @PostMapping("/postannounce")
    public ResponseData<Boolean> postAnnounce(@RequestBody Announce announce){
        // 判断公告标题或内容是否为空
        if (announce.getTitle() == null || announce.getContext() == null){
            return null;
        }
        return returnBoolean(adminService.postAnnounce(announce));
    }

    @Operation(summary = "查看公告")
    @GetMapping("/getannounce")
    public ResponseData<Object> getAnnounce(){
        return returnObject(adminService.getAnnounces());
    }

    @Operation(summary = "获取最新时间的公告")
    @GetMapping("/getlastestannounce")
    public ResponseData<Object> getLatestAnnounce(){
        return returnObject(adminService.getLatestAnnounce());
    }

    @Operation(summary = "查看请假列表")
    @GetMapping("/getleaves")
    public ResponseData<Object> getLeaves(Integer currentPage,Integer size){
        return returnObject(adminService.getLeaveInfo(currentPage,size));
    }

    @Operation(summary = "通过请假申请")
    @PutMapping("/passleave")
    public ResponseData<Boolean> passLeave(@RequestBody Leave leave){
        if (leave.getId() == null){
            return null;
        }
        return returnBoolean(adminService.passStudentLeave(leave));
    }

    @Operation(summary = "驳回请假申请")
    @PutMapping("/refuseleave")
    public ResponseData<Boolean> refuseLeave(@RequestBody Leave leave){
        if (leave.getId() == null){
            return null;
        }
        return returnBoolean(adminService.refuseStudentLeave(leave));
    }

    @Operation(summary = "获取课程调整申请")
    @GetMapping("/getupdatecourse")
    public ResponseData<Object> getInsertCourse(Integer currentPage,Integer size){
        return returnObject(adminService.getInsertCourse(currentPage,size));
    }


    @Operation(summary = "审核排课申请")
    @PutMapping("/checkInsertCourse")
    public ResponseData<Boolean> checkInsertCourse(Integer id,Integer state,String courseNumber){
       if (id == null || state == null || courseNumber == null){
           return null;
       }
        return returnBoolean(adminService.checkInsertCourse(id,state,courseNumber));
    }


}
